//
//  ShowQRcodeView.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/28.
//  Copyright © 2020 tym. All rights reserved.
//

#import "ShowQRcodeView.h"
#import "SGQRCodeObtain.h"
#import "UIView+ZFFrame.h"
#import "NSString+Option.h"
#import "Sizes.h"
#import "UserTool.h"
#import "UIImageView+YPImage.h"
#import "UserModel.h"
@interface ShowQRcodeView()
@property(nonatomic,weak) IBOutlet UIView *conView;
@property(nonatomic,weak) IBOutlet UIImageView *headImage;
@property(nonatomic,weak) IBOutlet UIImageView *qrCodeImage;
@property(nonatomic,weak) IBOutlet UILabel *familyNameLab;
@end

@implementation ShowQRcodeView

-(void)awakeFromNib{
    [super awakeFromNib];
    //{"familyId":1}
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.conView.layer.cornerRadius = 14.5;
    
    NSDictionary *dic = @{@"familyId":@([UserTool getCurrentFamily].familyId)
    };
    NSString *jsonStr = [NSString  convertToJsonData:dic];
    self.qrCodeImage.image = [SGQRCodeObtain generateQRCodeWithData:jsonStr size:100];
    self.familyNameLab.text = [UserTool getCurrentFamily].familyName;
    
    if ([[UserTool getLogInUser] getEquipmentImage].length) {
        [self.headImage yp_setImageUlr:[[UserTool getLogInUser] getEquipmentImage]];
    }
}

-(IBAction)cancelAction:(id)sender{
    
    [self removeFromSuperview];
}

-(void)dealloc{
    NSLog(@"展示二维码 释放");
}

+(void)showQRCodeView{
    
    ShowQRcodeView *view = [[[NSBundle mainBundle] loadNibNamed:@"ShowQRcodeView" owner:self options:nil] lastObject];
    UIWindow *keyWindow = [[[UIApplication sharedApplication] windows] firstObject];
    view.frame = keyWindow.bounds;
    [keyWindow addSubview:view];
}



/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
